#include "ui_number.h"

CUINumber::CUINumber(long int nValue)
    :  
    CUIText("0", "bomberman"),
    m_nValue(nValue)
{
    // This initialises the string text value
    setValue(nValue);
}

CUINumber &CUINumber::operator+=(long int nOther)
{
    updateValue(nOther);
    return *this;
}

CUINumber CUINumber::operator+(long int nOther) const
{
    CUINumber copy(m_nValue);
    copy += nOther;
    return copy;
}

CUINumber &CUINumber::operator-=(long int nOther)
{
    updateValue(-nOther);
    return *this;
}

CUINumber CUINumber::operator-(long int nOther) const
{
    CUINumber copy(m_nValue);
    copy -= nOther;
    return copy;
}

CUINumber &CUINumber::operator*=(long int nOther)
{
    setValue(getValue() * nOther);
    return *this;
}

CUINumber CUINumber::operator*(long int nOther) const
{
    CUINumber copy(m_nValue);
    copy *= nOther;
    return copy;
}

CUINumber &CUINumber::operator/=(long int nOther)
{
    setValue(getValue() / nOther);
    return *this;
}

CUINumber CUINumber::operator/(long int nOther) const
{
    CUINumber copy(m_nValue);
    copy /= nOther;
    return copy;
}

CUINumber &CUINumber::operator++()
{
    updateValue(1);
    return *this;
}

CUINumber &CUINumber::operator--()
{
    updateValue(-1);
    return *this;
}

CUINumber CUINumber::operator++(int)
{
    CUINumber copy(m_nValue);
    ++(*this);
    return copy;
}

CUINumber CUINumber::operator--(int)
{
    CUINumber copy(m_nValue);
    --(*this);
    return copy;
}

void CUINumber::setValue(long int nValue)
{
    m_nValue = nValue;

    // Convert number to string and update the text
    stringstream sstream;
    sstream << nValue;

    setText(sstream.str());
}

void CUINumber::updateValue(long int nValue)
{
    setValue(getValue() + nValue);
}

long int CUINumber::getValue() const
{
    return m_nValue;
}